<template>
  <!-- 这里做了一个小小的优化 -->
  <div v-if="Object.keys(goods).length !== 0" class="base-info">
     <div class="info-title">{{goods.title}}</div>
     <div class="info-price">
       <span class="n-price">{{goods.newPrice}}</span>
       <span class="o-price">{{goods.oldPrice}}</span>
       <span v-if="goods.discount" class="discount">{{goods.discount}}</span>
     </div>

      <!-- 销量 收藏 退货补运费 -->
     <div class="info-other">
       <span>{{goods.columns[0]}}</span>
       <span>{{goods.columns[1]}}</span>
       <span>{{goods.services[goods.services.length-1].name}}</span>
     </div>

      <!-- 图片 + 七天无理由退货 或者 图片 + 72小时发货-->
      <!-- v-for 除了可以遍历数组之外，还可以遍历数字
           v-for="n in 10" 从 1 遍历到 10 -->
     <div class="info-service">
       <span class="info-service-item" v-for="index in goods.services.length-1" :key="index">
         <img :src="goods.services[index - 1].icon" alt="">
         <span>{{goods.services[index - 1].name}}</span>
       </span>
     </div>
  </div>
</template>

<script>
  export default {
    name: "DetailBaseInfo",
    props: {
      goods: {
        type: Object,
        default() {
          return {}
        }
      }
    },
  }
</script>

<style scoped>
  .base-info {
    margin-top: 16px;
    padding: 0 8px;
    color: #999;
    border-bottom: 5px solid #f2f5f8;
  }

  .info-title {
    font-size: 14px;
    color: #222;
  }

  .info-price {
    margin-top: 10px;
  }

  .info-price .n-price {
    font-size: 24px;
    color: var(--color-high-text);
  }

  .info-price .o-price {
    font-size: 13px;
    margin-left: 5px;
    text-decoration: line-through;
  }

  .info-price .discount {
    /* 设置这个字体的目的就是使字体变小 */
    font-size: 12px;
    /* 里面的字体是 auto */
    padding: 2px 5px;
    color: #fff;
    background-color: var(--color-high-text);
    border-radius: 8px;
    margin-left: 5px;


    /* 让元素上浮一些，使用相对定位即可 */
    position: relative;
    bottom: 8px;
  }

  .info-other {
    margin-top: 15px;
    height: 30px;
    line-height: 30px;
    display: flex;
    font-size: 13px;
    border-bottom: 1px solid rgba(100, 100, 100, .1);
    justify-content: space-between;
  }

  .info-service {
    display: flex;
    justify-content: space-between;
    height: 60px;
    line-height: 60px;
  }

  .info-service-item img {
    width: 14px;
    height: 14px;
    /* 微调你就使用相对定位 */
    position: relative;
    top: 2px;
  }

  .info-service-item span {
    font-size: 13px;
    color: #333;
  }
</style>
